
import { ValidateType } from '@/types'

const getValidateMsg = (type: ValidateType, values: string[]) => {
    const baseValue = values[0]
    let msg = ''
    switch (type) {
        case ValidateType.username:
            if (baseValue.length < 3 || baseValue.length > 50) {
                msg = '用户名必须为3~50个字符';
            }
            break
        case ValidateType.email:
            if (!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(baseValue)) {
                msg = '邮箱不符合规则';
            }
            break
        case ValidateType.password:
            if (baseValue.length < 6) {
                msg = '密码不能少于6位';
            }
            break
        case ValidateType.confirmPassword:
            if (values[0] !== values[1]) {
                msg = '密码不一致';
            }
            break
        default:
            break
    }

    return msg
};

export default getValidateMsg